package com.aurora.base.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class Base64 {
	/**
	 * 编码
	 * 
	 * @param bstr
	 * @return String
	 */
	public static String encode(byte[] bstr) {
		return new sun.misc.BASE64Encoder().encode(bstr);
	}

	/**
	 * 解码
	 * 
	 * @param str
	 * @return string
	 */
	public static byte[] decode(String str) {
		byte[] bt = null;
		try {
			sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
			bt = decoder.decodeBuffer(str);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return bt;
	}
	
	public static String byteTostr(byte[] bytes) {
		String srt = "";
		String nickname = "";
		try {
			srt = new String(bytes,"UTF-8");
			System.out.println("srt: "+srt);
//			nickname = new String(srt.getBytes(
//			  "ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return srt;
	}
	
    /** 
     * @param args 
     */  
//    public static void main(String[] args) {  
//    	Base64 te = new Base64();  
//        String aa = "更多更多";  
//        aa = te.encode(aa.getBytes());  
//        System.out.println("----aa:"+aa);  
//        String str = aa;  
//        String str2 = new String(te.decode(str));  
//        System.out.println("-----str2:"+str2);  
//    }  
}
